<template>
	<view>
		<view class="box">
			<image src="../../static/lgo.png" mode=""></image>
		</view>
		<view class="login-box" v-if="showLogin">
			<view class="wx" @click="denglu()">
				<image src="../../static/wx.png" mode=""></image>
				<p style="font-size: 28rpx;">微信登录</p>
			</view>
			<!-- 			<view class="dd">
				<radio @click="cs()" shape="square" style="transform: scale(0.5);" :checked="bl" />我已阅读并同意
				<text @click="goPage(1)">《用户协议》</text>和<text @click="goPage(2)">《隐私政策》</text>
			</view> -->
		</view>
		<view class="reg-box" v-else>
			<button type="primary" @click="goLogin">我要注册</button>
		</view>
		
		<view class="tips-box">
			<!-- <text>仅限物流公司司机注册登录</text> -->
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bl: true,
				showLogin: true,
			}
		},
		methods: {
			cs() {
				this.bl = this.bl ? false : true;
			},
			denglu() {
				if (!this.bl) uni.showToast({ title: '请先同意协议', icon: 'none', })
				else {
					uni.showLoading({ mask: true, title: '登录中...' })
					uni.login({
						provider: 'weixin',
						success: (loginRes) => {
							console.log(loginRes);
							this.$rqt.driverLogin({ code: loginRes.code }).then(res => {
								console.log(res)
								uni.showToast({ title: res.msg, icon: 'none', })
								uni.setStorageSync('token', res.data.userInfo.token)
								uni.setStorageSync('avatar', res.data.userInfo.avatar)
								uni.setStorageSync('userInfo', res.data.userInfo)
								if (res.msg == "登录成功") {
									let share_id = ''
									share_id = uni.getStorageSync('share_id');
									// 如果有share_id
									if (share_id) {
										// uni.removeStorageSync('share_id');
									}
									setTimeout(() => {
										uni.reLaunch({
											url: "/pages/index/index?id=" +
												share_id,
										})
									}, 850)
								}
							})
						},
						complete: res => {
							uni.hideLoading()
						}
					})
				}

			},
			goPage(id) {
				if (id == 1) {
					uni.navigateTo({
						url: "/pages/subpack1/userAgreement/userAgreement"
					})
				} else {
					uni.navigateTo({
						url: "/pages/subpack1/privacyAgreement/privacyAgreement"
					})
				}
			},
			goLogin() {
				this.showLogin = true
			}
		}
	}
</script>

<style scoped>
	.dd>text {
		color: #F1572F;
	}

	.dd {
		margin-top: 41px;
		font-size: 12px;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.wx {
		margin-top: 100px;
		text-align: center;
	}

	.wx>image {
		width: 90rpx;
		height: 77rpx;
	}

	.box {
		width: 100%;
		text-align: center;
		margin-top: 213px;
	}

	.box>image {
		width: 240rpx;
		height: 132rpx;
		background: #FFFFFF;
	}

	.tips-box {
		display: flex;
		justify-content: center;
		font-size: 24rpx;
		color: #9E9E9E;
		margin-top: 20rpx;
	}

	.reg-box {
		display: flex;
		justify-content: center;
		margin-top: 50rpx;
	}
</style>